// Globals
float3 lightDirection;
float3 color;

texture colortex;
texture normaltex;
texture depthtex;

sampler ColorTex
{
	Texture = <colortex>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

sampler NormalTex
{
	Texture = <normaltex>;
	MinFilter = POINT;
	MagFilter = POINT;
	MipFilter = POINT;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

sampler DepthTex
{
	Texture = <depthtex>;
	MinFilter = POINT;
	MagFilter = POINT;
	MipFilter = POINT;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

// Define a vertex shader output structure;
struct OutputVS
{
    float4 posH:POSITION0;
    float2 texCoord: TEXCOORD0;
};

// Vertex shader -------------------------------------------------------------------------------------
OutputVS TransformVS( float3 position:POSITION0, float2 texCoord:TEXCOORD0 )
{
	// output structure
	OutputVS outVS;
	
	outVS.posH = float4( position, 1.0f );
	outVS.texCoord = texCoord;
	
    return outVS;
}


// Pixel Shader ---------------------------------------------------------------------------
float4 TransformPS( OutputVS outVS ): COLOR0
{
	float3 normal = tex2D( NormalTex, outVS.texCoord ).xyz;
	float depth = tex2D( DepthTex, outVS.texCoord ).r;
	float3 lightVec = - normalize( lightDirection );
	float3 normalLight = max( 0, dot( normal, lightVec ) );
	float3 diffuse = normalLight * color;
	
	return float4( diffuse , 1.0f );
}

// ----------------------------------------------------------------------------------------
technique Basic
{
    pass P0
    {
        vertexShader = compile vs_2_0 TransformVS();
        pixelShader  = compile ps_2_0 TransformPS();
      
		ShadeMode = Flat;
        //FillMode = WIREFRAME;
        
        CullMode = CCW;
    }
}
